//
//  CollectionDetailViewController.m
//  AoJi
//
//  Created by mac on 15/2/28.
//  Copyright (c) 2015年 xuanheng. All rights reserved.
//

#import "CollectionDetailViewController.h"
#import "CollectionDetailCell.h"
#import "UIImageView+WebCache.h"

@interface CollectionDetailViewController ()

@end

@implementation CollectionDetailViewController{
    UITableView                 *_tableView;
    NSMutableArray          *_dataSource;
    NSMutableDictionary     *_param;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    _param = [NSMutableDictionary dictionary];
    [self setNavigationTitle];
    _dataSource = [NSMutableArray array];
    [self loadData];
}

- (void)setTableView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Mainwidth, MainHeight - self.navigationController.navigationBar.frame.size.height - 20) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}

- (void)setNavigationTitle{
    switch (self.flag) {
        case Scholl:
            self.title = @"学校详情";
            _param[@"type"] = @"school";
            break;
        case Activity:
            self.title = @"活动详情";
            _param[@"type"] = @"activity";
            break;
        case Interview:
            self.title = @"面试详情";
            _param[@"type"] = @"lecture";
            break;
        case Route:
            self.title = @"路线详情";
            _param[@"type"] = @"route";
            break;
        case Course:
            self.title = @"课程详情";
            _param[@"type"] = @"course";
            break;
        default:
            break;
    }
}

-(void)loadData
{
    [YHNetwork getInformationWithReguestType:RequestTypeGet WithParameters:_param WithApi:@"me/favorite" WhenSuccess:^(NSMutableDictionary *response) {
        _dataSource = response;
        NSLog(@"%@",response);
        [self setTableView];
    } WhenFailure:^(NSError *failure) {
        NSLog(@"%@",failure);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"detailCell";
    CollectionDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[CollectionDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    NSDictionary *dict = _dataSource[indexPath.row];
    [cell.icon sd_setImageWithURL:[NSURL URLWithString:dict[@"object"][@"logo"]] placeholderImage:nil];
    NSLog(@"%@",dict[@"object"][@"cschool"]);
    NSLog(@"%@",dict[@"object"][@"eschool"]);
    NSLog(@"%@",dict[@"object"][@"eschool"]);
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

@end
